package com.ruoyi.web.controller.vantController.shopController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.supe.GroupJoint;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderMaster;
import com.ruoyi.system.service.zhaungxiuservice.shopService.GroupJointService;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 拼团拼接Controller
 *
 * @author ruoyi
 * @date 2021-01-30
 */
@RestController
@RequestMapping("/api/joint")
public class GroupJointController extends BaseController {

    @Autowired
    private GroupJointService groupJointService;

    @Autowired
    private OrderMasterService orderMasterService;

    /**
     * 查询拼团拼接列表
     */

    @GetMapping("/list")
    public List<GroupJoint> list(GroupJoint groupJoint)
    {
        List<GroupJoint> list = groupJointService.selectGroupJointList(groupJoint);
        return list;
    }


    /**
     * 获取拼团拼接详细信息
     */

    @GetMapping(value = "/getInfo/{jointId}")
    public AjaxResult getInfo(@PathVariable("jointId") Integer jointId)
    {
        return AjaxResult.success(groupJointService.selectGroupJointById(jointId));
    }

    @GetMapping(value = "/listJointById/{productId}")
    public AjaxResult listJointById(@PathVariable("productId") Integer productId)
    {
        return AjaxResult.success(groupJointService.listJointById(productId));
    }

    /**
     * 新增拼团拼接
     */

    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody GroupJoint groupJoint)
    {
        return toAjax(groupJointService.insertGroupJoint(groupJoint));
    }

    /**
     * 修改拼团拼接
     */

    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody GroupJoint groupJoint)
    {
        return toAjax(groupJointService.updateGroupJoint(groupJoint));
    }


    @PutMapping(value = "/updatepintuan")
    public AjaxResult updatepintuan(@RequestBody OrderMaster orderMaster)
    {
        Integer numorderId = orderMaster.getNumorderId();
        orderMaster.setOrderId(numorderId);
        return toAjax(orderMasterService.updatepintuan(orderMaster));
    }

    /**
     * 删除拼团拼接
     */

    @DeleteMapping("/remove/{jointIds}")
    public AjaxResult remove(@PathVariable Integer[] jointIds)
    {
        return toAjax(groupJointService.deleteGroupJointByIds(jointIds));
    }

}
